import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:fluttertz/jsonserialize/tzuser/data.dart';
import 'package:fluttertz/utils/global.dart';
import 'package:webview_flutter/webview_flutter.dart';

class Wtfk extends StatefulWidget {
  Wtfk({Key key}) : super(key: key);

  _WtfkState createState() => _WtfkState();
}

class _WtfkState extends State<Wtfk> {
  final Completer<WebViewController> _controller =
      Completer<WebViewController>();

  @override
  void initState() {
    super.initState();
    // if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
  }

  @override
  Widget build(BuildContext context) {
    TzUserData userData = G.user.data;
    String url =
        "http://aps.acciot.com.tw/index/tzapp/message2?mobile=${userData.mobile}";

    var stack = new Stack(
      children: <Widget>[
        Container(
          decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage("lib/assets/images/tz/bg.png"),
                fit: BoxFit.cover,
              )),
          child: Text("aa"),
        ),
        WebView(
          initialUrl: url,
          javascriptMode: JavascriptMode.unrestricted,
          onWebViewCreated: (WebViewController webViewController) {
            _controller.complete(webViewController);
          },
          javascriptChannels: <JavascriptChannel>[
            // _toasterJavascriptChannel(context),
          ].toSet(),
          navigationDelegate: (NavigationRequest request) {
            if (request.url.startsWith('https://www.youtube.com/')) {
              print('blocking navigation to $request}');
              return NavigationDecision.prevent;
            }
            print('allowing navigation to $request');
            return NavigationDecision.navigate;
          },
          onPageStarted: (String url) {
            print('Page started loading: $url');
          },
          onPageFinished: (String url) {
            print('Page finished loading: $url');
          },
          gestureNavigationEnabled: true,
        ),
      ],
    );

    return Container(
        decoration: BoxDecoration(
            image: DecorationImage(
          image: AssetImage("lib/assets/images/tz/bg.png"),
          fit: BoxFit.cover,
        )),
        child: Scaffold(
          backgroundColor: Colors.transparent,
          appBar: customAppbar(
            title: '問題反饋',
            context: context, //null不显示返回按钮
          ),
          body: Center(
            child: stack
          )
        ));
  }

  // JavascriptChannel _toasterJavascriptChannel(BuildContext context) {
  //   return JavascriptChannel(
  //       name: 'Toaster',
  //       onMessageReceived: (JavascriptMessage message) {
  //         Scaffold.of(context).showSnackBar(
  //           SnackBar(content: Text(message.message)),
  //         );
  //       });
  // }

}


